/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NewJPanel.java
 *
 * Created on 14-nov-2011, 15:09:41
 */
package aexbanner;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Polygon;
import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;

/**
 *
 * @author Dion
 */
public class NewJPanel extends javax.swing.JPanel {

    MockEffectenbeurs beurs = new MockEffectenbeurs();
    public static int ruimte = 500;
    public static int beginX = 0;
    ArrayList<String> Teksten = new ArrayList<String>();
    Timer timer = new Timer();
    
    class mytask extends TimerTask {

    public mytask() {
    }

    @Override
    public void run() {
               NewJPanel.beginX --;
               repaint();
        
    }
    
}
    /** Creates new form NewJPanel */
    public NewJPanel() {
        initComponents();
        for (int i = 0; i < beurs.getKoersen().size(); i++) {
            Teksten.add(beurs.Koersen.get(i).getFondsnaam() + "  (" + beurs.Koersen.get(i).getKoers() + ")");
        }

        timer.schedule(new mytask(), 20, 20);
        
        int x = 0;
       for (int j = 0; j < Teksten.size(); j++) {
        x += Teksten.get(j).length() * 10;                
       }
       if (x > 500)
       ruimte = x;
    }
    

    
    @Override
    public void paintComponent(Graphics g){
    super.paintComponent(g);	   // erases background
    Graphics2D g2 = (Graphics2D)g;   //cast for java2

    // my graphics:
    g2.setColor(new Color(255,255,255));
    g2.fillRect(0,0,500,50);
    g2.setColor(new Color(0,0,0));
    

    
    int x = beginX;
        for (int i = 0; i < Teksten.size(); i++) {
                        
            x += 10; 
            int x2 = x;
            while (x2 < 0)
            {
                    x2 += ruimte;
            }
            g.drawString(Teksten.get(i), x2 - ruimte, 25); 
                
              if(beurs.Koersen.get(i).getGestegen() == true)
              {
		int[] xs = { x2-10, x2-20, x2-15 };
		int[] ys = { 25, 25, 17 };
                
                Color c = new Color(0,128,0);
                g.setColor(c);
                
		Polygon triangle = new Polygon(xs, ys, xs.length);
                
		g.fillPolygon(triangle);
              }
              else
              {
                  int[] xs = { x2-10, x2-20, x2-15 };
                  int[] ys = { 17, 17, 25 };
                  g.setColor(Color.red);
                  
                  
		Polygon triangle = new Polygon(xs, ys, xs.length);
                
		g.fillPolygon(triangle);
              }
               
              
                g.setColor(Color.black);
            g2.drawString(Teksten.get(i), x2, 25);  
            x += Teksten.get(i).length() * 9;
        }
      
  }
    
    
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 407, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 67, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}

